<?php

namespace app\modules\Finance\models;

use Yii;
use dektrium\user\models\User;


/**
 * This is the model class for table "receive_account".
 *
 * @property integer $id
 * @property string $account
 * @property string $remark
 * @property integer $user_id
 * @property string $created_at
 * @property string $updated_at
 */
class ReceiveAccount extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'receive_account';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['account'], 'required'],
            [['user_id', 'type'], 'integer'],
            [['created_at', 'updated_at'], 'safe'],
            [['account', 'remark'], 'string', 'max' => 255],
        ];
    }

    // 保存前处理
    public function beforeSave($insert) {//{{{
        if($insert){
            $this->created_at = date("Y-m-d H:i:s");
            $this->user_id    = Yii::$app->user->id;
        }
        return parent::beforeSave($insert);
    }//}}}



	//  获取录入人
	public function getUser(){
		return $this->hasOne(User::className(), ['id' => 'user_id']);
	}   
    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => Yii::t('app', 'ID'),
            'account' => Yii::t('app', '收款账号'),
            'remark' => Yii::t('app', '备注'),
            'user_id' => Yii::t('app', '录入人'),
            'type' => Yii::t('app', '收款类型'),
            'created_at' => Yii::t('app', 'Created At'),
            'updated_at' => Yii::t('app', 'Updated At'),
        ];
    }
}
